package control
{
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	import org.swizframework.Swiz;
	
	public class StockController
	{
		
		public static const USER_WANTS_STOCK_PRICES : String = "userWantsStockPrices";
		public static const STOCK_REQUEST_STARTED : String = "stockRequestStarted";
		public static const STOCK_REQUEST_COMPLETE : String = "stockRequestComplete";
		public static const SERVER_REQUEST_FAILED: String = "serverRequestFailed";
		
		[Bindable]
		public var stockQuotes : ArrayCollection
		
		public var stockService : RemoteObject
		
		public function StockController()
		{
			stockQuotes = new ArrayCollection()
		}
		
		[Mediate( event="userWantsStockPrices" )]
		public function loadStockPrices() : void
		{
			stockService.getStockPrices()
		}
		
		[Mediate( event="stockRequestComplete", properties="stockPrices" ) ]
		public function stockPricesReceived( stockPrices : Array ) : void
		{
			stockQuotes.source = stockPrices
		}

		[Mediate( event="serverRequestFailed" )]
		public function serverError() : void
		{
			Alert.show( "Oops!  Server died!" );
		}

	}
}